package com.example.evanproject.controller;
import com.baomidou.mybatisplus.extension.api.R;
import com.example.evanproject.domain.Course;
import com.example.evanproject.domain.Coursechapter;
import com.example.evanproject.domain.Teacher;
import com.example.evanproject.service.CourseService;
import com.example.evanproject.service.CoursechapterService;
import com.example.evanproject.service.TeacherService;

import com.example.evanproject.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController
@CrossOrigin
@RequestMapping("course")
public class CourseController {
    @Autowired
    private CourseService courseService;

    @RequestMapping("selectall")
    public AjaxResult selecttest(){
        return AjaxResult.success(courseService.selecttest()) ;
    }

    @RequestMapping("selectall2")
    public R selectall2(Integer pageNum, Integer pageSize, String courseName){
        return courseService.selectall2(pageNum,pageSize,courseName);
    }


    @RequestMapping("selectallByid")
    public AjaxResult  selecttestbyId(Integer cId){

        return AjaxResult.success(courseService.selectListById(cId)) ;

    }

//    轮播管理的课程

    @RequestMapping("rotation")
    public AjaxResult selectrotation(){

        return AjaxResult.success(courseService.selectrotation()) ;
    }

    @Autowired
    private CoursechapterService courseChapterService;
    @Autowired
    private TeacherService teacherService;
    //获取课程信息+课时信息+老师信息
    @RequestMapping("courseandlesson")
    public AjaxResult  courseandlessoninfo(Integer id){
        System.out.println("这是第一次");
        //获取课程
        Course course=courseService.selectListById(id);
        //霍获取目录信息
        List<Coursechapter> list1= courseChapterService.selectcourseallinfo(id);
        //获取老师信息（就是从注册表中获取老师信息）
        Teacher teacher= teacherService.selectteacherinfo(Integer.valueOf(course.getTId()));
        List<Object> list=new ArrayList<>();
        Map<String,Object> map=new HashMap<>();
        map.put("course",course);
        map.put("teater",teacher);
        map.put("courselist",list1);

        return AjaxResult.success(map);
    }

    //获取个人信息的课程
    @RequestMapping("/selectbyid")
    public AjaxResult selectcourssebyuserid(Integer userid){

        return AjaxResult.success(courseService.selectcoursebyuserid(userid)) ;
    }
//    获取老师的全部课程（以及携带参加的学生的人数）
    @RequestMapping("allcoursebyteacherid")
public  AjaxResult allcoursebyteacherid(Integer tid){

        return AjaxResult.success(courseService.allcoursebyteacherid(tid)) ;
    }
//  查询单个课程信息以及带有参加的学生的信息
    @RequestMapping("coursebyteacherid")
    public  AjaxResult coursebyteacherid(Integer courseid){

        return AjaxResult.success(courseService.coursebyteacherid(courseid)) ;
    }



//    新建一个课程信息()
    @PostMapping("addcourse")
    public AjaxResult addcourselist(String courseName, Integer tId, String courseNote, String courseStarttime, String courseEndtime, Integer courseTyid, Integer courseMoney, @RequestParam(value = "file", required = false) MultipartFile file){

        return AjaxResult.success(courseService.addcourselist(courseName,tId,courseNote,courseStarttime,courseEndtime,courseTyid,courseMoney,file))  ;


    }


//    筛选课程(按照名字分类)


//    //删除课程（也要删除 学生加入课程里面的那个课程）
  @RequestMapping("delectlist")
    public  AjaxResult delectcoursebyid(Integer courseId){
        return AjaxResult.success(courseService.delectcoursebyid(courseId)) ;
    }

//    课程排行榜
    @RequestMapping("couserBarnk")
 public AjaxResult couserBarnk(){
     return AjaxResult.success(courseService.couserBarnk()) ;
 }
}
